import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/15 9:27
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1,7,3,6,5,6};
        solution.pivotIndex(nums);
    }
    public int pivotIndex(int[] nums) {
        int n = nums.length;
        int[] preSum = new int[n+1];
        for (int i = 0; i < n; i++) {
            preSum[i+1] = preSum[i] + nums[i];
        }
        for (int i = 0; i < n; i++) {
            if (preSum[i] == preSum[n]- preSum[i+1]) {
                return i;
            }
        }
        return -1;
    }
}
